package com.hmdp.controller;


import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.hmdp.dto.Result;
import com.hmdp.entity.ShopType;
import com.hmdp.service.IShopTypeService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/shop-type")
public class ShopTypeController {
    @Resource
    private IShopTypeService typeService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @GetMapping("list")
    public Result queryTypeList() {
//        String listJson = stringRedisTemplate.opsForValue().get("shop:type；list");
//        JSONArray objects = JSONUtil.parseArray(listJson);

        List<ShopType> typeList = typeService
                .query().orderByAsc("sort").list();
//        String toJsonStr = JSONUtil.toJsonStr(typeList);
//        System.out.println("__________"+toJsonStr);
//        stringRedisTemplate.opsForList().leftPushAll("shop:type:",toJsonStr);
//        String temp;
//        while ((temp=stringRedisTemplate.opsForList().leftPop("shop:type:"))!=null){
//            System.out.println(temp);
//        }
        return Result.ok(typeList);
    }
}
